<?php
/**
* ErrorController - The default error controller class
*
* @author
* @version
*/
class Error_ErrorController extends Apm_Controller_Base
{
	/**
	* This action handles
	* - Application errors
	* - Errors in the controller chain arising from missing
	* controller classes and/or action methods
	*/
	public function errorAction()
	{
		$this->_data = $this->getParameters();
		$errors = $this->_getParam('error_handler');
		$exception = $errors['exception'];
		$e_message = $exception->getMessage();
		$e_trace = $exception->getTraceAsString();
/*		
		echo('<b>[Error Message]</b><br><br>');
		echo($e_message);
		echo('<hr style="margin:20px 0px;">');
		echo('<b>[Stack Trace]</b>');
		echo('<pre>'.$e_trace.'</pre>');
*/		
		$e_log = "\r\n".'[Error Message]'."\r\n".$e_message."\r\n".'[Stack Trace]'."\r\n".$e_trace;
        
        $config = Zend_Registry::get('config');
        
        switch ($errors->type) {
			case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_OTHER:
				$this->getResponse()->setRawHeader('HTTP/1.1 500 Internal Server Error')->sendResponse();
                if ($this->_data['isMobile'] == 1){
                    exit;
                }
                if(isset($this->_data['mode'])){
                    if($this->_data['mode']=='xml' || $this->_data['mode'] == 'json'){
                        exit;
                    }
                }
                // エラーページにリダイレクト
                $url = '';
                $url .= $config->apm->baseurl;
                if(strpos($_SERVER["REQUEST_URI"], '/sp/') !== false){
                	$url .= 'sp/500/';
                }
                else{
                	$url .= 'sitemap/500error.html';
                }
                Apm_Util::redirect($url, array(), true);
                exit;
			break;
			default:
                // エラーページにリダイレクト
				$this->getResponse()->setRawHeader('HTTP/1.1 404 Not Found')->sendResponse();
                $url = '';
                $url .= $config->apm->baseurl;

                if(strpos($_SERVER["REQUEST_URI"], '/sp/') !== false){
                	$url .= 'sp/404/';
                }
                else{
                	$url .= 'sitemap/404error.html';
                }
                Apm_Util::redirect($url, array(), true);
                exit;
			break;
		}
	}
}
?>
